﻿/*!
 * Onejs Tips Plugin Version 1.0.0
 * Date: 2012-05-16 17:45:11
 * Copyright © OneStudio, Inc. All Rights Reserved. 
 */

(function( $, onejs, window ){

var document = window.document,
    expando = 'TIP' + (+new Date),
	panel,

onetips = function()
{
    return onejs.tool.clone( onejstips );
},

onejstips =
{
    init: function( config )
	{
		if( !config || !config.elms ) return;
		
		if( config.elms.nodeType )
		    config.elms = [config.elms];
			
		if( typeof config.content === 'string' )
		    config.content = [config.content];
		
		panel = onejs.plugin.panel();
		panel.init({ elms:[{id:'onetips',tpl:'default'}] });
		
		onejs.tool.extend( config, onetips.setting );
		
		var that = this, i = 0, l = config.elms.length,
		    tips = that.tips = panel.get('onetips'), elem;
		
		for( ; i < l; i++ )
		{
		    elem = config.elms[i];
			
			$(elem).bind('mouseout',function(){
			    tips.hide();
			}).bind('mouseover',function(){
			    tips.content( config.content[i] || this.innerHTML )
				.show().follow( this, config.position, config.offset );
			});
		}
		
		that.config = config;
		
		return that;
	},
	
	content: function( txt )
	{
	    this.tips.content( txt );
		
		return this;
	}
};
	
onetips.setting =
{	
    content: null,
	position: ['left','bottom'],
	offset: [0,0]
};	
	
onejs.plugin.tips = onetips;	
	
})( window.jQuery, window.onejs, window );